package com.example.chronicdisease.service;

import com.example.chronicdisease.mapper.DoctorMapper;
import com.example.chronicdisease.pojo.Doctor;
import com.example.chronicdisease.response.ChronicDiseaseException;
import com.example.chronicdisease.response.ChronicDiseaseExceptionEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



@Service
public class DoctorServiceImpl implements DoctorService {
    @Autowired
    DoctorMapper doctorMapper;
    //前端发送包含医生编号和密码的 JSON 数据到 /doctor/login 接口。
    //Controller 层调用 Service 层的 login 方法。
    //Service 层根据医生编号从数据库中查询医生信息。
    //如果查询到医生信息，返回医生信息；否则，抛出异常。
    @Override
    //处理登录业务
    public Doctor login(Doctor doctor){
        Doctor doctor1 = doctorMapper.selectBydocCode(doctor.getDocCode());
        System.out.println("!!! DEBUG ONLY !!! Password: " + doctor1.getPassword());
        if(doctor1 == null){
            //不存在抛出异常
            throw new ChronicDiseaseException(ChronicDiseaseExceptionEnum.DOCTOR_IS_NOT_EXIST);
        }

        // 返回时清除敏感信息
        doctor1.setPassword(null);
        return doctor1;
    }
}
